[mirrors]
http://downloads.ghostscript.com/public/ghostscript-9.16.tar.bz2

[vars]
filesize=29163348
sha512=6886b6d4f542563c8a87f9ea243736b5b97d2e4c277e6fc8cba0b7b07b7f394c2cff940ada1cfbb8f8e3916df53044837cbfcb1d5c22df865641496766630599

[deps]
expat
freetype
libpng
libtiff
libjpeg
zlib
lcms2
jbig2dec

[build]
# may need some additional fonts
# TODO: add packages for them
# http://www.linuxfromscratch.org/blfs/view/7.4/pst/gs.html
# http://downloads.sourceforge.net/gs-fonts/ghostscript-fonts-std-8.11.tar.gz
# http://downloads.sourceforge.net/gs-fonts/gnu-gs-fonts-other-6.0.tar.gz


# get rid of in-tree lib copies, so the system ones are picked up
rm -rf expat freetype lcms lcms2 jpeg libpng tiff lcms lcms2 cups/libs jbig2dec

printf "#!/bin/sh\necho -lfreetype -I$butch_root_dir$butch_prefix/include/freetype2\n" > freetype-config
chmod +x freetype-config
export PATH="$PWD:$PATH"

[ -n "$CROSS_COMPILE" ] && \
  xconfflags="--host=$($CC -dumpmachine|sed 's/musl/gnu/')"
endian=$("$K"/endiancheck.sh)
CPPFLAGS="-D_GNU_SOURCE" \
CFLAGS="$optcflags $optldflags  -Wl,-rpath-link=$butch_root_dir$butch_prefix/lib" \
  ./configure -C --prefix="$butch_prefix" $xconfflags \
  --enable-"$endian"-endian \
  --enable-dynamic \
  --disable-static \
  --disable-cups \
  --with-system-libtiff \
  --disable-compile-inits \
  --with-jbig2dec \
  --enable-fontconfig \
  --enable-freetype \
  --with-x \
  --disable-gtk \
  --without-luratech
# due to a missing GSLCMS2SRCDIR variable, the build for 2 files ends up
# including -I/include, which pulls in the hosts headers
sed -i 's/GLLCMS2CC=.*$/GLLCMS2CC=$(CC) $(LCMS2_CFLAGS) $(CFLAGS) $(I_)$(GLI_) $(II)FOO$(LCMS2SRCDIR)BAR$(D)include$(_I) $(GLF_)/' base/lib.mak

make CC="$HOSTCC" base/genarch base/genconf base/echogs
mkdir -p obj/aux soobj/aux
for i in echogs genarch genconf ; do
	cp base/"$i" obj/aux
	cp base/"$i" soobj/aux
done

make -j$MAKE_THREADS so
make DESTDIR="$butch_install_dir" soinstall

dest="$butch_install_dir""$butch_prefix"
# in the dynamic build, gsx and gsc are equivalent to gs,
# but they apparently use some different screen output mode.
# so it may be better to symlink gsc to gs.
ln -s gsx "$dest"/bin/gs
